﻿// json_4.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "JSONParse.h"

std::string testCreateJson();

int main()
{
	CJSONParse parse(testCreateJson().c_str());
	cJSON* root = parse.GetRootItem();
	std::map<CData, CData> map_data;
	parse.printJson(root, map_data);
	std::cout << map_data["int"].ToInt() << std::endl;
	std::cout << map_data["string"].c_str() << std::endl;
	std::cout << map_data["double"].ToDouble() << std::endl;
	std::cout << map_data["true"].ToInt() << std::endl;
	std::cout << map_data["false"].ToInt() << std::endl;

	int temp = 0, temp2 = 0;
	CData temp3 = 0;
	parse.GetValueNumber(root, "true", temp);
	parse.GetValueNumber(root, "false", temp2);
	parse.GetValueAuto(root, "int", temp3);
	std::cout << temp3.ToInt() << std::endl;
	//system("pause");
	return 0;
}

std::string testCreateJson() {
	cJSON* JsonObject1 = cJSON_CreateObject();
	cJSON_AddItemToObject(JsonObject1, "int", cJSON_CreateNumber(200));
	cJSON_AddItemToObject(JsonObject1, "string", cJSON_CreateString("success"));
	cJSON_AddItemToObject(JsonObject1, "double", cJSON_CreateNumber(1.3603611579));
	cJSON_AddItemToObject(JsonObject1, "true", cJSON_CreateTrue());
	cJSON_AddItemToObject(JsonObject1, "false", cJSON_CreateFalse());

	char* SendJson = cJSON_Print(JsonObject1);
	printf("%s\n", SendJson);
	return SendJson;
}